package org.bigdata.framework.core.protocol;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.bigdata.framework.core.model.BalanceAccount;
import org.bigdata.framework.core.model.CountAccount;
import org.bigdata.framework.core.model.IpLoginNumber;
import org.bigdata.framework.core.model.MemberProject;
import org.bigdata.framework.core.model.PayOrder;
import org.bigdata.framework.core.model.PayOrderDetail;
import org.bigdata.framework.core.model.PayRecharge;
import org.bigdata.framework.core.model.Project;
import org.bigdata.framework.core.model.ProjectProduct;
import org.bigdata.framework.core.model.TimeAccount;
import org.bigdata.framework.core.service.IBalanceAccountService;
import org.bigdata.framework.core.service.ICountAccountService;
import org.bigdata.framework.core.service.IIpLoginNumberService;
import org.bigdata.framework.core.service.IMemberProjectService;
import org.bigdata.framework.core.service.IPayOrderDetailService;
import org.bigdata.framework.core.service.IPayOrderService;
import org.bigdata.framework.core.service.IPayRechargeService;
import org.bigdata.framework.core.service.IProjectProductService;
import org.bigdata.framework.core.service.IProjectService;
import org.bigdata.framework.core.service.ITimeAccountService;
import org.bigdata.framework.core.utils.MybatisPlusTools;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.plugins.Page;

public class PayService implements IPayService {

	private static final Logger LOG = Logger.getLogger(PayService.class);

	@Autowired
	private IBalanceAccountService balanceAccountService;
	@Autowired
	private ICountAccountService countAccountService;
	@Autowired
	private IProjectService projectService;
	@Autowired
	private ITimeAccountService timeAccountService;
	@Autowired
	private IMemberProjectService memberProjectService;
	@Autowired
	private IProjectProductService projectProductService;
	@Autowired
	private IPayRechargeService payRechargeService;
	@Autowired
	private IPayOrderService payOrderService;
	@Autowired
	private IPayOrderDetailService payOrderDetailService;
	@Autowired
	private IIpLoginNumberService ipLoginNumberService;

	@Override
	public BalanceAccount saveBalanceAccount(BalanceAccount balanceAccount) {

		boolean r = balanceAccountService.insert(balanceAccount);
		if (r) {
			return balanceAccount;
		}
		return null;
	}

	@Override
	public BalanceAccount editBalanceAccount(BalanceAccount balanceAccount) {

		boolean r = balanceAccountService.updateAllColumnById(balanceAccount);
		if (r) {
			return balanceAccount;
		}
		return null;
	}

	@Override
	public void deleteBalanceAccount(BalanceAccount balanceAccount) {

		boolean r = balanceAccountService.deleteById(balanceAccount.getId());
		if (r) {
			System.out.println("balanceAccount 删除成功>>>"
					+ balanceAccount.getId());
		}
	}

	@Override
	public BalanceAccount findBalanceAccount(Integer id) {

		return balanceAccountService.selectById(id);
	}

	@Override
	public List<BalanceAccount> getBalanceAccount() {

		return balanceAccountService.selectList(null);
	}

	@Override
	public List<BalanceAccount> getBalanceAccount(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return balanceAccountService
				.selectPage(
						new Page<BalanceAccount>(pageNumber, pageSize),
						new MybatisPlusTools<BalanceAccount>()
								.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getBalanceAccountCount(HashMap<String, Object> queryParams) {

		return balanceAccountService
				.selectCount(new MybatisPlusTools<BalanceAccount>()
						.getEwByCount(queryParams));
	}

	@Override
	public CountAccount saveCountAccount(CountAccount countAccount) {

		boolean r = countAccountService.insert(countAccount);
		if (r) {
			return countAccount;
		}
		return null;
	}

	@Override
	public CountAccount editCountAccount(CountAccount countAccount) {

		boolean r = countAccountService.updateAllColumnById(countAccount);
		if (r) {
			return countAccount;
		}
		return null;
	}

	@Override
	public void deleteCountAccount(CountAccount countAccount) {

		boolean r = countAccountService.deleteById(countAccount.getId());
		if (r) {
			System.out.println("countAccount 删除成功>>>" + countAccount.getId());
		}
	}

	@Override
	public CountAccount findCountAccount(Integer id) {

		return countAccountService.selectById(id);
	}

	@Override
	public List<CountAccount> getCountAccount() {

		return countAccountService.selectList(null);
	}

	@Override
	public List<CountAccount> getCountAccount(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return countAccountService.selectPage(
				new Page<CountAccount>(pageNumber, pageSize),
				new MybatisPlusTools<CountAccount>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getCountAccountCount(HashMap<String, Object> queryParams) {

		return countAccountService
				.selectCount(new MybatisPlusTools<CountAccount>()
						.getEwByCount(queryParams));
	}

	@Override
	public Project saveProject(Project project) {

		boolean r = projectService.insert(project);
		if (r) {
			return project;
		}
		return null;
	}

	@Override
	public Project editProject(Project project) {

		boolean r = projectService.updateAllColumnById(project);
		if (r) {
			return project;
		}
		return null;
	}

	@Override
	public void deleteProject(Project project) {

		boolean r = projectService.deleteById(project.getId());
		if (r) {
			System.out.println("project 删除成功>>>" + project.getId());
		}
	}

	@Override
	public Project findProject(Integer id) {

		return projectService.selectById(id);
	}

	@Override
	public List<Project> getProject() {

		return projectService.selectList(null);
	}

	@Override
	public List<Project> getProject(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return projectService.selectPage(
				new Page<Project>(pageNumber, pageSize),
				new MybatisPlusTools<Project>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getProjectCount(HashMap<String, Object> queryParams) {

		return projectService.selectCount(new MybatisPlusTools<Project>()
				.getEwByCount(queryParams));
	}

	@Override
	public TimeAccount saveTimeAccount(TimeAccount timeAccount) {

		boolean r = timeAccountService.insert(timeAccount);
		if (r) {
			return timeAccount;
		}
		return null;
	}

	@Override
	public TimeAccount editTimeAccount(TimeAccount timeAccount) {

		boolean r = timeAccountService.updateAllColumnById(timeAccount);
		if (r) {
			return timeAccount;
		}
		return null;
	}

	@Override
	public void deleteTimeAccount(TimeAccount timeAccount) {

		boolean r = timeAccountService.deleteById(timeAccount.getId());
		if (r) {
			System.out.println("timeAccount 删除成功>>>" + timeAccount.getId());
		}
	}

	@Override
	public TimeAccount findTimeAccount(Integer id) {

		return timeAccountService.selectById(id);
	}

	@Override
	public List<TimeAccount> getTimeAccount() {

		return timeAccountService.selectList(null);
	}

	@Override
	public List<TimeAccount> getTimeAccount(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return timeAccountService.selectPage(
				new Page<TimeAccount>(pageNumber, pageSize),
				new MybatisPlusTools<TimeAccount>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getTimeAccountCount(HashMap<String, Object> queryParams) {

		return timeAccountService
				.selectCount(new MybatisPlusTools<TimeAccount>()
						.getEwByCount(queryParams));
	}

	@Override
	public MemberProject saveMemberProject(MemberProject memberProject) {

		boolean r = memberProjectService.insert(memberProject);
		if (r) {
			return memberProject;
		}
		return null;
	}

	@Override
	public MemberProject editMemberProject(MemberProject memberProject) {

		boolean r = memberProjectService.updateAllColumnById(memberProject);
		if (r) {
			return memberProject;
		}
		return null;
	}

	@Override
	public void deleteMemberProject(MemberProject memberProject) {

		boolean r = memberProjectService.deleteById(memberProject.getId());
		if (r) {
			System.out.println("memberProject 删除成功>>>" + memberProject.getId());
		}
	}

	@Override
	public MemberProject findMemberProject(Integer id) {

		return memberProjectService.selectById(id);
	}

	@Override
	public List<MemberProject> getMemberProject() {

		return memberProjectService.selectList(null);
	}

	@Override
	public List<MemberProject> getMemberProject(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return memberProjectService.selectPage(
				new Page<MemberProject>(pageNumber, pageSize),
				new MybatisPlusTools<MemberProject>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getMemberProjectCount(HashMap<String, Object> queryParams) {

		return memberProjectService
				.selectCount(new MybatisPlusTools<MemberProject>()
						.getEwByCount(queryParams));
	}

	@Override
	public ProjectProduct saveProjectProduct(ProjectProduct projectProduct) {

		boolean r = projectProductService.insert(projectProduct);
		if (r) {
			return projectProduct;
		}
		return null;
	}

	@Override
	public ProjectProduct editProjectProduct(ProjectProduct projectProduct) {

		boolean r = projectProductService.updateAllColumnById(projectProduct);
		if (r) {
			return projectProduct;
		}
		return null;
	}

	@Override
	public void deleteProjectProduct(ProjectProduct projectProduct) {

		boolean r = projectProductService.deleteById(projectProduct.getId());
		if (r) {
			System.out.println("projectProduct 删除成功>>>"
					+ projectProduct.getId());
		}
	}

	@Override
	public ProjectProduct findProjectProduct(Integer id) {

		return projectProductService.selectById(id);
	}

	@Override
	public List<ProjectProduct> getProjectProduct() {

		return projectProductService.selectList(null);
	}

	@Override
	public List<ProjectProduct> getProjectProduct(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return projectProductService
				.selectPage(
						new Page<ProjectProduct>(pageNumber, pageSize),
						new MybatisPlusTools<ProjectProduct>()
								.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getProjectProductCount(HashMap<String, Object> queryParams) {

		return projectProductService
				.selectCount(new MybatisPlusTools<ProjectProduct>()
						.getEwByCount(queryParams));
	}

	@Override
	public PayRecharge savePayRecharge(PayRecharge payRecharge) {
		boolean r = payRechargeService.insert(payRecharge);
		if (r) {
			return payRecharge;
		}
		return null;
	}

	@Override
	public PayRecharge editPayRecharge(PayRecharge payRecharge) {
		boolean r = payRechargeService.updateAllColumnById(payRecharge);
		if (r) {
			return payRecharge;
		}
		return null;
	}

	@Override
	public void deletePayRecharge(PayRecharge payRecharge) {
		boolean r = payRechargeService.deleteById(payRecharge.getId());
		if (r) {
			System.out.println("payRecharge 删除成功>>>"
					+ payRecharge.getId());
		}
		
	}

	@Override
	public PayRecharge findPayRecharge(Integer id) {
		return payRechargeService.selectById(id);
	}

	@Override
	public List<PayRecharge> getPayRecharge() {
		return payRechargeService.selectList(null);
	}

	@Override
	public List<PayRecharge> getPayRecharge(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return payRechargeService.selectPage(
						new Page<PayRecharge>(pageNumber, pageSize),
						new MybatisPlusTools<PayRecharge>()
								.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getPayRechargeCount(HashMap<String, Object> queryParams) {

		return payRechargeService.selectCount(new MybatisPlusTools<PayRecharge>()
						.getEwByCount(queryParams));
	}

	@Override
	public PayOrder savePayOrder(PayOrder payOrder) {
		boolean r = payOrderService.insert(payOrder);
		if (r) {
			return payOrder;
		}
		return null;
	}

	@Override
	public PayOrder editPayOrder(PayOrder payOrder) {
		boolean r = payOrderService.updateAllColumnById(payOrder);
		if (r) {
			return payOrder;
		}
		return null;
	}

	@Override
	public void deletePayOrder(PayOrder payOrder) {
		boolean r = payOrderService.deleteById(payOrder.getId());
		if (r) {
			System.out.println("payOrder 删除成功>>>"
					+ payOrder.getId());
		}
	}

	@Override
	public PayOrder findPayOrder(Integer id) {
		return payOrderService.selectById(id);
	}

	@Override
	public List<PayOrder> getPayOrder() {
		return payOrderService.selectList(null);
	}

	@Override
	public List<PayOrder> getPayOrder(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		return payOrderService.selectPage(
				new Page<PayOrder>(pageNumber, pageSize),
				new MybatisPlusTools<PayOrder>()
						.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getPayOrderCount(HashMap<String, Object> queryParams) {
		return payOrderService.selectCount(new MybatisPlusTools<PayOrder>()
				.getEwByCount(queryParams));
	}

	@Override
	public PayOrderDetail savePayOrderDetail(PayOrderDetail payOrderDetail) {
		boolean r = payOrderDetailService.insert(payOrderDetail);
		if (r) {
			return payOrderDetail;
		}
		return null;
	}

	@Override
	public PayOrderDetail editPayOrderDetail(PayOrderDetail payOrderDetail) {
		boolean r = payOrderDetailService.updateAllColumnById(payOrderDetail);
		if (r) {
			return payOrderDetail;
		}
		return null;
	}

	@Override
	public void deletePayOrderDetail(PayOrderDetail payOrderDetail) {
		boolean r = payOrderDetailService.deleteById(payOrderDetail.getId());
		if (r) {
			System.out.println("payOrderDetail 删除成功>>>"
					+ payOrderDetail.getId());
		}
	}

	@Override
	public PayOrderDetail findPayOrderDetail(Integer id) {
		return payOrderDetailService.selectById(id);
	}

	@Override
	public List<PayOrderDetail> getPayOrderDetail() {
		return payOrderDetailService.selectList(null);
	}

	@Override
	public List<PayOrderDetail> getPayOrderDetail(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		return payOrderDetailService.selectPage(
				new Page<PayOrderDetail>(pageNumber, pageSize),
				new MybatisPlusTools<PayOrderDetail>()
						.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getPayOrderDetailCount(HashMap<String, Object> queryParams) {
		return payOrderDetailService.selectCount(new MybatisPlusTools<PayOrderDetail>()
				.getEwByCount(queryParams));
	}

	@Override
	public IpLoginNumber saveIpLoginNumber(IpLoginNumber ipLoginNumber) {
		boolean r = ipLoginNumberService.insert(ipLoginNumber);
		if (r) {
			return ipLoginNumber;
		}
		return null;
	}

	@Override
	public IpLoginNumber editIpLoginNumber(IpLoginNumber ipLoginNumber) {
		boolean r = ipLoginNumberService.updateAllColumnById(ipLoginNumber);
		if (r) {
			return ipLoginNumber;
		}
		return null;
	}

	@Override
	public void deleteIpLoginNumber(IpLoginNumber ipLoginNumber) {
		boolean r = ipLoginNumberService.deleteById(ipLoginNumber.getId());
		if (r) {
			System.out.println("ipLoginNumber 删除成功>>>"
					+ ipLoginNumber.getId());
		}
	}

	@Override
	public IpLoginNumber findIpLoginNumber(Integer id) {
		return ipLoginNumberService.selectById(id);
	}

	@Override
	public List<IpLoginNumber> getIpLoginNumber() {
		return ipLoginNumberService.selectList(null);
	}

	@Override
	public List<IpLoginNumber> getIpLoginNumber(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		return ipLoginNumberService.selectPage(
				new Page<IpLoginNumber>(pageNumber, pageSize),
				new MybatisPlusTools<IpLoginNumber>()
						.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getIpLoginNumberCount(HashMap<String, Object> queryParams) {
		return ipLoginNumberService.selectCount(new MybatisPlusTools<IpLoginNumber>()
				.getEwByCount(queryParams));
	}

}
